package cn.funeralobjects.upms.repository;

import cn.funeralobjects.common.repository.CommonCloudRepository;
import cn.funeralobjects.upms.entity.ECustomPath;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.EntityGraph;

import java.util.List;
import java.util.Optional;

/**
 * @author FuneralObjects
 * Create date: 2020/5/27 4:14 PM
 */
public interface ECustomPathRepository extends CommonCloudRepository<ECustomPath, Integer> {


    @Override
    @EntityGraph("ECustomPath.withRoles")
    List<ECustomPath> findAllByCode(Iterable<String> codes);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    Page<ECustomPath> findAll(boolean enable, Pageable pageable);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    List<ECustomPath> findAll(boolean enable, Sort sort);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    List<ECustomPath> findAll(boolean enable);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    List<ECustomPath> findAll();

    @Override
    @EntityGraph("ECustomPath.withRoles")
    List<ECustomPath> findAll(Sort sort);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    List<ECustomPath> findAllById(Iterable<Integer> integers);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    <S extends ECustomPath> List<S> findAll(Example<S> example);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    <S extends ECustomPath> List<S> findAll(Example<S> example, Sort sort);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    List<ECustomPath> findAllByName(Iterable<String> names);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    Page<ECustomPath> findAll(Pageable pageable);

    @Override
    @EntityGraph("ECustomPath.withRoles")
    <S extends ECustomPath> Page<S> findAll(Example<S> example, Pageable pageable);

    /**
     * 查询名称是否存在
     *
     * @param scope   scope
     * @param name    name
     * @param delSalt delSalt
     * @return true - 存在
     */
    boolean existsAllByScopeAndNameAndDelSalt(String scope, String name, Integer delSalt);

    /**
     * 查询名称是否存在
     *
     * @param scope   scope
     * @param name    name
     * @param delSalt delSalt
     * @return true - 存在
     */
    boolean existsAllByScopeAndNameAndIdNotAndDelSalt(String scope, String name, Integer id, Integer delSalt);

    /**
     * 在范围中根据名称查询实体
     *
     * @param scope   scope
     * @param name    name
     * @param delSalt delSalt
     * @return entity
     */
    Optional<ECustomPath> findFirstByScopeAndNameAndDelSalt(String scope, String name, Integer delSalt);
}
